﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;

namespace nextGeneration_app
{
    public partial class Resetpassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void notmebtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("teacher_forgotPassword.aspx");
        }

        protected void resetbtn_Click(object sender, EventArgs e)
        {
            string email = (string)(Session["email"]);
            string temp = null;//GenerateStrongPassword(8);
            string userId = (string)(Session["loginUserID"]);
            string usertype = (string)(Session["loginUserType"]);

            //Create the message
            MailMessage mail = new MailMessage();

            //add the email address
            mail.To.Add(email);

            //add our emailAddress
            mail.From = new MailAddress("frozenunrivaled@gmail.com");

            //email's subject
            mail.Subject = "Confirmation Your Password";

            //email's Body
            mail.Body = "Hi" + " " + userId + ",<br>" +
               "<br>You have requested to reset your" + usertype + " account password. To complete your request, please <br>" +
               "<br>enter the following confirmation code:<br>" +
                temp + "<br><br>Please note: for your protection, a copy of this email has been sent to all the email addresses associated with your account.";

            //set email's body to HTML
            mail.IsBodyHtml = true;

            //set up smtp client, gmail specific settings
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

            //SSL must be available for gmail
            client.EnableSsl = true;

            //Gmail Account Credentials
            NetworkCredential credentials =new NetworkCredential("babeyeemon1st@gmail.com", "nov131992");

            //Add credentials to smpt client
            client.Credentials = credentials;

            try
            {
                //ty to Send the Email
                client.Send(mail);
            }
            catch
            {
                messagelbl.Text = "Fail";
            }
            confirmation c = new confirmation(temp);
            teacher_dbManager myManager = new teacher_dbManager();
            teacher_dbManager.confirmation(c);
            Response.Redirect("confirmation.aspx");



        }    
      
   }


}